function varargout = MatematikaB(varargin)
% MATEMATIKAB MATLAB code for MatematikaB.fig
%      MATEMATIKAB, by itself, creates a new MATEMATIKAB or raises the existing
%      singleton*.
%
%      H = MATEMATIKAB returns the handle to a new MATEMATIKAB or the handle to
%      the existing singleton*.
%
%      MATEMATIKAB('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MATEMATIKAB.M with the given input arguments.
%
%      MATEMATIKAB('Property','Value',...) creates a new MATEMATIKAB or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before MatematikaB_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to MatematikaB_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help MatematikaB

% Last Modified by GUIDE v2.5 27-Apr-2011 23:00:54

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @MatematikaB_OpeningFcn, ...
                   'gui_OutputFcn',  @MatematikaB_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before MatematikaB is made visible.
function MatematikaB_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to MatematikaB (see VARARGIN)

% Choose default command line output for MatematikaB
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes MatematikaB wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = MatematikaB_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


function MatematikaBHitungButton_Callback(hObject, eventdata, handles)
global soal1;
global numsoal;
global metode;
global x0 y0 xr yr h h_idx n;
global xn y01 numy0;
global fxy;
global fungsi1;
global numfungsi;
global metodestring;
global hasil1; 
global numhasil;

cancount = 1;
fxy = @(x,y)(exp(-2*x)-2*y);
x0 = 0; y0 = 0.1;
xr = str2double(get(handles.MatematikaBInput_t,'String'));
h_idx = get(handles.MatematikaBPopup_h,'Value');
switch(h_idx)
    case{1}
        h = 0.2;
    case{2}
        h = 0.1;
    case{3}
        h = 0.05;
end;
metode = get(handles.MatematikaBPopup_metode,'Value');

switch(metode)
    case{1}
        [n yr] = Euler(fxy,[x0 xr],y0,h);
        display(yr);
        metodestring = 'Euler';
    case{2}
        [n yr] = Heun(fxy,[x0 xr],y0,h);
        display(yr);
        metodestring = 'Heun';
    case{3}
        [n yr] = Runge_Kutta( [x0,xr], h, y0, fxy, 3);
        display(yr);
        metodestring = 'Runge-Kutta Orde 3';
    case{4}
        [n yr] = Runge_Kutta( [x0 xr], h, y0, fxy, 4);
        display(yr);
        metodestring = 'Runge-Kutta Orde 4';
    case {5}
        n = (xr - x0) / h;
        if (n < 4) 
            cancount = 0;
            msgbox('n yang diperlukan minimal 4. Ubah nilai h atau t');
        else
            [n yr] = Adam_Moulton([x0 xr],h,y0,fxy);
            display(yr);
            metodestring = 'P-C Adams-Moulton';
        end
end;

if (cancount)
    set(handles.MatematikaBOutput_y, 'String', num2str(yr));

    %------------------------------------------------%
    % Pembuatan report
    %------------------------------------------------%
    % Soal
    soal1 = 'y'' = exp(-2*t) - 2*y';
    numsoal = 1;
    % Variabel
    % x0 = x0 (variabel dan globalnya sama)
    xn = xr;
    % h = h (variabel dan globalnya sama)
    % n = n (variabel dan globalnya sama)
    y01 = y0;
    numy0 = 1;
    % Fungsi untuk perhitungan
    fungsi1 = func2str(fxy);
    numfungsi = 1;
    % Hasil
    hasil1 = yr;
    numhasil = 1;
    % Generate Report
    report('DifferentialEquation');
end

function MatematikaBPopup_metode_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function MatematikaBPopup_metode_Callback(hObject, eventdata, handles)

function MatematikaBPopup_h_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function MatematikaBPopup_h_Callback(hObject, eventdata, handles)

function MatematikaBInput_t_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function MatematikaBInput_t_Callback(hObject, eventdata, handles)
